/*
 * Droplet.cpp
 *
 * Created: 5/11/2012 4:13:57 PM
 *  Author: common
 */ 

#include <avr/io.h>
#include <math.h>
#include <util/delay.h>

#include "motor.h"
#include "RGB_LED.h"

int main(void)
{
	motor_init();
	RGB_LED_init();
	
	uint8_t dir = 0, speed = 0, i = 0;
	
	while (1)
	{
		for (dir = 0; dir < 6; dir++)
		{
			// Blink red 10 times on reset
			for (i = 0; i < 10; i++)
			{
				set_red(255);
				_delay_ms(500);
				set_red(0);
				_delay_ms(500);
			}
		
			// Blink green dir times to indicate direction
			for (i = 0; i < dir; i++)
			{
				set_green(255);
				_delay_ms(500);
				set_green(0);
				_delay_ms(500);
			}
				
			// Blink blue speed / 10 times to indicate speed
			for (i = 0; i < speed / 10; i++)
			{
				set_blue(255);
				_delay_ms(500);
				set_blue(0);
				_delay_ms(500);
			}		
		
			// Move in direction
			move(dir, speed);
			_delay_ms(5000);
			stop();
		}		
		
		speed += 10;
		if (speed > 250) speed = 0;
	}	
}